<style>
    th{
        text-align: center;}
</style>
<div class="table-responsive">
    <table class="table table-bordered " style="text-align: center;" id="printable-table">
        <thead>
            <tr >
                <th >项目</th>
                <th>单位</th>
                <th>测试方法</th>
                <th>测试结果</th>
                <th>公差</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td rowspan="2">密度<br>Density</td>
                <td>g/cm²</td>
                <td rowspan="2">JISK6401</td>
                <td>{$row.density}</td>
                <td>±{$row.densityallowance}%</td>
            </tr>

            <tr>
                <td>kg/m³</td>
                
                <td>{$row.density*1000}</td>
                <td>±{$row.densityallowance}%</td>
            </tr>
          
            <tr>
                <td>厚度<br>Thickness</td>
                <td>mm</td>
                <td>Thickness gauge</td>
                <td>{$row.thickness}</td>
                <td>±{$row.thicknessallowance}%</td>
            </tr>     

            <tr>
                <td rowspan="2">25%壓縮荷重<br>25%CLD</td>
                <td>Mpa</td>
                <td rowspan="2">ASTMD3574</td>
                <td>{$row.cld}</td>
                <td>±{$row.cldallowance}</td>
            </tr>
            <tr>
                <td>kg/cm²</td>
               
                <td>{$row.cld*10}</td>
                <td>±{$row.cldallowance*10}</td>
            </tr>

            <tr>
                <td rowspan="2">壓缩永久形</td>
                <td rowspan="2">%/td>
                <td>ASTM D 3574-95
                    Test D @23℃</td>
                <td>{$row.astm23}</td>
                <td>≤5%</td>
            </tr>
            <tr>
                
                <td>ASTM D 3574-95
                    Test D @70℃</td>
                <td>{$row.astm70}</td>
                <td>≤10%</td>
            </tr>
           
            <tr>
                <td>建议长期使用温度</td>
                <td>℃</td>
                <td></td>
                <td>80</td>
                <td></td>
            </tr>
            <tr>
                <td>建议短期使用温度</td>
                <td>℃</td>
                <td></td>
                <td>120</td>
                <td></td>
            </tr>
        </tbody>
    </table>
</div>
<!-- 打印按钮 -->
<button class="btn btn-primary btn-block" onclick="printTable()">打印表格</button>

<script>
    function printTable() {
        // 获取表格内容
        var tableContent = document.getElementById("printable-table").outerHTML;
    
        // 创建一个新的窗口
        var printWindow = window.open('', '', 'width=800,height=600');
    
        // 写入表格内容到新窗口
        printWindow.document.write(`
            <html>
                <head>
                    <title>打印表格</title>
                    <style>
                        table {
                            width: 100%;
                            border-collapse: collapse;
                        }
                        table, th, td {
                            border: 1px solid black;
                        }
                        th, td {
                            padding: 8px;
                            text-align: left;
                        }
                        .table-bordered {
                            border: 1px solid #dee2e6;
                        }
                        .table-striped tbody tr:nth-of-type(odd) {
                            background-color: rgba(0, 0, 0, 0.05);
                        }
                    </style>
                </head>
                <body>
                    ${tableContent}
                </body>
            </html>
        `);
    
        // 关闭文档写入
        printWindow.document.close();
    
        // 触发打印
        printWindow.print();
    }
    </script>